﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YinfangWeb.BLL.Model;
using YinfangWeb.Model;

namespace YinfangWeb.DAL
{
    public partial class UserDataDAO
    {
        #region 获取单条记录 通过用户名和身份
        /// <summary>
		/// 获取单条记录 通过用户名
		/// </summary>
		/// <param name="UserName">用户名</param>
		/// <returns>实体</returns>
        public UserData GetInfoByUserName(int identity, string username)
        {
            var sql = "SELECT * FROM UserData WHERE UserName = @UserName and UserIdentity=@UserIdentity";
            using (var conn = ConnectionFactory.CreateConnection())
            {
                var model = conn.QueryFirstOrDefault<UserData>(sql, new { UserName = username, UserIdentity = identity });
                return model;
            }
        }
        #endregion
        #region 获取单条记录 通过Token
        /// <summary>
		/// 获取单条记录 通过Token
		/// </summary>
		/// <param name="token">Token</param>
		/// <returns>实体</returns>
        public UserData GetInfoByToken(string token)
        {
            var sql = "SELECT * FROM UserData inner join UserToken on UserData.UserDataID=UserToken.UserDataID where Token=@Token";
            using (var conn = ConnectionFactory.CreateConnection())
            {
                var model = conn.QueryFirstOrDefault<UserData>(sql, new { Token = token });
                return model;
            }
        }
        #endregion
    }
}
